<?php
use common\models\db\AdminPower;
use wodrow\yii2wtools\tools\JsBlock;
use yii\helpers\Html;

/**
 * @var \yii\web\View $this
 * @var \fztadmin\modules\rbac\models\forms\AdminPower $model
 * @var array $tree_data
 * @var string $attribute
 */
?>

<div class="role-set-menu-fun">
    <?php foreach($tree_data as $k => $v): ?>
        <?php
            $checkbox = Html::checkbox($model->formName() . "[{$attribute}][]", $v['isChecked']?true:false, [
                'value' => $v['id'],
                'data-path' => $v['path'],
            ]);
        ?>
        <?php if ($v['_child'] ?? null): ?>
            <h5>
                <label>
                    <?=$checkbox; ?><?= $v['name'] ?>
                </label>
            </h5>
            <div class="" style="padding-left: 2em;">
                <?php
                echo $this->render('index', [
                    'tree_data' => $v['_child'],
                    'model' => $model,
                    'attribute' => $attribute,
                ]);
                ?>
            </div>
        <?php else: ?>
            <div class="checkbox-line">
                <label class="pull-left"  style="min-width: 3em;padding-right: 2em;">
                    <?=$checkbox ?><?= $v['name'] ?>
                </label>
            </div>
            <?php if($v['type'] == AdminPower::TYPE_FUN): ?>
                <?php if(count($tree_data) == $k + 1): ?>
                    <div class="clearfix"></div>
                <?php endif; ?>
            <?php else: ?>
                <div class="clearfix"></div>
            <?php endif; ?>
        <?php endif; ?>
    <?php endforeach; ?>
</div>

<?php JsBlock::begin(); ?>
    <script>
        $(function () {});
    </script>
<?php JsBlock::end(); ?>